// 01背包问题的变形，这里可以将价值等同于体积
#include <iostream>
#include <algorithm>
using namespace std;

const int N = 20010, M = 35;
int f[N], a[M];
int v, n;

int main()
{
    cin >> v >> n;
    for (int i = 1; i <= n; ++i)
    {
        int v1;
        cin >> v1;
        for (int j = v; j >= v1; --j)
            f[j] = max(f[j], f[j - v1] + v1);
    }
    cout << v - f[v] << endl;
    return 0;
}